/**
 * @Title: MrOWeatherUtil.java
 * @author zengshuai shi
 * @date 2015年11月3日 下午4:03:53
 */
package com.shanghaionstar.mro.util;

import android.content.Context;

import com.onstar.cn.common.util.CommonUtil;
import com.shanghaionstar.R;
import com.shanghaionstar.mro.bean.weather.Item;
import com.shanghaionstar.mro.bean.weather.WeatherBean;

import java.util.Iterator;
import java.util.List;

/**
 * @author zengshuai shi
 * @ClassName: MrOWeatherUtil
 * @Description: TODO
 * @date 2015年11月3日 下午4:03:53
 */
public class MrOWeatherUtil {
    private Context context;

    /**
     * @Description: TODO
     * @author zengshuai shi
     * @date 2015年11月3日 下午4:04:15
     */
    public MrOWeatherUtil(Context context) {
        this.context = context;
    }

    public String getWeatherMsg(WeatherBean weatherBean) {
        int minTemperature = 0, maxTemperature = 0;
        String weatherDesc = null, city = null, msg = null;
        if (!CommonUtil.isNull(weatherBean.getAts().getWeather().getForecast().getDay())) {
            List<Item> items = weatherBean.getAts().getWeather().getForecast().getDay().get(0).getItem();
            Item forecast = null;
            if (!CommonUtil.isNull(items)) {
                Iterator it = items.iterator();
                while (it.hasNext()) {
                    forecast = (Item) it.next();
                    if (forecast.getDaynight().equals("1")) {
                        maxTemperature = Integer.valueOf(forecast.getTemperature());
                        weatherDesc = forecast.getWeather_desc();
                    } else if (forecast.getDaynight().equals("2")) {
                        minTemperature = Integer.valueOf(forecast.getTemperature());
                        weatherDesc = forecast.getWeather_desc();
                    }

                }
            }
            if (!CommonUtil.isNull(weatherBean.getAts())) {
                city = weatherBean.getAts().getCity();
            }
            if (!CommonUtil.isNull(getWeatherDec(weatherDesc))) {
                if (maxTemperature < 0) {
                    if (minTemperature < 0) {
                        msg = weatherBean.getAts().getCity() + context.getString(R.string.warm_d) + weatherDesc + context.getString(R.string.warm_max0)
                                + Math.abs(maxTemperature) + context.getString(R.string.warm_min0) + Math.abs(minTemperature) + context.getString(R.string.warm_spend_d)
                                + getWeatherDec(weatherDesc);
                    } else {
                        msg = weatherBean.getAts().getCity() + context.getString(R.string.warm_d) + weatherDesc + context.getString(R.string.warm_max0)
                                + Math.abs(maxTemperature) + context.getString(R.string.warm_min) + minTemperature + context.getString(R.string.warm_spend_d)
                                + getWeatherDec(weatherDesc);
                    }
                } else {
                    if (minTemperature < 0) {
                        msg = weatherBean.getAts().getCity() + context.getString(R.string.warm_d) + weatherDesc + context.getString(R.string.warm_max)
                                + maxTemperature + context.getString(R.string.warm_min0) + Math.abs(minTemperature) + context.getString(R.string.warm_spend_d)
                                + getWeatherDec(weatherDesc);
                    } else {
                        msg = weatherBean.getAts().getCity() + context.getString(R.string.warm_d) + weatherDesc + context.getString(R.string.warm_max)
                                + maxTemperature + context.getString(R.string.warm_min) + Math.abs(minTemperature) + context.getString(R.string.warm_spend_d)
                                + getWeatherDec(weatherDesc);
                    }
                }
            } else {
                if (maxTemperature < 0) {
                    if (minTemperature < 0) {
                        msg = weatherBean.getAts().getCity() + context.getString(R.string.warm_d) + weatherDesc + context.getString(R.string.warm_max0) + Math.abs(maxTemperature) + context.getString(R.string.warm_min0)
                                + Math.abs(minTemperature) + context.getString(R.string.warm_spend);
                    } else {
                        msg = weatherBean.getAts().getCity() + context.getString(R.string.warm_d) + weatherDesc + context.getString(R.string.warm_max0) + Math.abs(maxTemperature) + context.getString(R.string.warm_min)
                                + minTemperature + context.getString(R.string.warm_spend);
                    }
                } else {
                    if (minTemperature < 0) {
                        msg = weatherBean.getAts().getCity() + context.getString(R.string.warm_d) + weatherDesc + context.getString(R.string.warm_max) + maxTemperature + context.getString(R.string.warm_min0)
                                + Math.abs(minTemperature) + context.getString(R.string.warm_spend);
                    } else {
                        msg = weatherBean.getAts().getCity() + context.getString(R.string.warm_d) + weatherDesc + context.getString(R.string.warm_max) + maxTemperature + context.getString(R.string.warm_min)
                                + minTemperature + context.getString(R.string.warm_spend);
                    }
                }

            }
        }
        return msg;
    }

    public String getWeatherDec(String weatherDec) {
        String dec = "";
        WeatherType type = WeatherType.getWeatherTypeByDesc(weatherDec, context);
        if (type == null) {
            return dec;
        }
        switch (type) {
            case RAINSTORM:
                dec = context.getString(R.string.mro_weather_rainstorm);
                break;
            case HEAVYRAIN:
                dec = context.getString(R.string.mro_weather_heavyrain);
                break;
            case DUST:
                dec = context.getString(R.string.mro_weather_dust);
                break;
            case THUNDERSHOWER:
                dec = context.getString(R.string.mro_weather_thundershower);
                break;
            case HAZE:
                dec = context.getString(R.string.mro_weather_haze);
                break;
            case STRONG_SANDSTORM:
                dec = context.getString(R.string.mro_weather_strong_sandstorm);
                break;
            case MIST:
                dec = context.getString(R.string.mro_weather_mist);
                break;
            case SANDSTORM:
                dec = context.getString(R.string.mro_weather_sandstorm);
                break;
            case FOG:
                dec = context.getString(R.string.mro_weather_fog);
                break;
            case SLIGHTSNOW:
                dec = context.getString(R.string.mro_weather_slightsnow);
                break;
            case SLIGHTSNOW_TURN_SNOW:
                dec = context.getString(R.string.mro_weather_slightsnow_turn_snow);
                break;
            case LIGHTRAIN:
                dec = context.getString(R.string.mro_weather_lightrain);
                break;
            case LIGHTRAIN_TURN_RAIN:
                dec = context.getString(R.string.mro_weather_lightrain_turn_rain);
                break;
            case BLOWINGSAND:
                dec = context.getString(R.string.mro_weather_blowingsand);
                break;
            case SHOWER:
                dec = context.getString(R.string.mro_weather_shower);
                break;
            case SNOW:
                dec = context.getString(R.string.mro_weather_snow);
                break;
            case SNOW_TURN_HEAVYSNOW:
                dec = context.getString(R.string.mro_weather_snow_turn_heavysnow);
                break;
            case RAIN:
                dec = context.getString(R.string.mro_weather_rain);
                break;
            case RAIN_TURN_HEAVYRAIN:
                dec = context.getString(R.string.mro_weather_rain_turn_heavyrain);
                break;
            case SUNNY:
                dec = context.getString(R.string.mro_weather_sunny);
                break;
            case CLOUDY:
                dec = context.getString(R.string.mro_weather_cloud);
                break;
        }
        return dec;
    }
}
